//
//  GuideSearchView.m
//  ZhiHuiLiJiang
//
//  Created by work on 2018/11/15.
//  Copyright © 2018年 王雅鹏. All rights reserved.
//搜索框View

#import "GuideSearchView.h"

@implementation GuideSearchView
-(instancetype)initWithFrame:(CGRect)frame with:(NSString *)str{
    if (self == [super initWithFrame:frame]) {
        [self addView:str];
    }
    return self;
}
-(void)addView:(NSString *)str{
    _scanBtn = [BYVS createBtnNorIcon:@"身份切换" selIcon:@"" addSubView:self];
    [_scanBtn addTarget:self action:@selector(scanBtnClick) forControlEvents:UIControlEventTouchUpInside];
    if ([str isEqualToString:@""]) {
        _scanBtn.hidden = YES;
    }else{
        _scanBtn.hidden = NO;
    }
    //搜索的背景
    _searchBgView = [BYVS createViewBGColor:RGBA(226, 226, 226, 1) addSubView:self];
    _searchBgView.layer.cornerRadius = BY_Height(57/2.0);
    _searchBgView.layer.masksToBounds = YES;
    //城市名
    _cityLab = [BYVS createLabText:@"丽江" font:BYPTFont28 labColor:RGBA(80, 80, 80,1) addSubView:_searchBgView];
    _cityLab.userInteractionEnabled = YES;
    [_cityLab sizeToFit];
    //分割线
    _lineView = [BYVS createViewBGColor:RGBA(80, 80, 80,1) addSubView:_searchBgView];
    //搜索按钮
    _searchBtn = [BYVS createBtnImg:@"搜索" titStr:@"搜索" titColor:RGBA(152, 152, 152,1) titFont:BYPTFont28 addSubView:_searchBgView];
    _searchBtn.imageEdgeInsets = UIEdgeInsetsMake(0, BY_Width(-200), 0, BY_Width(210));
    _searchBtn.titleEdgeInsets = UIEdgeInsetsMake(0, BY_Width(-400), 0, 0);
    [_searchBtn addTarget:self action:@selector(seachBtnClick) forControlEvents:UIControlEventTouchUpInside];

    BY_kWeakSelf(ws);
    //扫一扫
    [_scanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(ws.mas_top).offset(BY_StatusBar_H + BY_Height(16));
        make.height.offset(BY_Height(52));
        make.width.offset(BY_Height(52));
        make.right.equalTo(ws.mas_right).offset(BY_Width(-24));
    }];
    //搜索的背景
    [_searchBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(ws.mas_left).offset(BY_Width(24));
        make.centerY.equalTo(ws.scanBtn.mas_centerY);
        if ([str isEqualToString:@""]) {
            make.width.offset(BY_ScreenWidth - BY_Width(36) - BY_Width(24));
        }else{
            make.width.offset(BY_ScreenWidth - BY_Width(36) - BY_Width(24) - BY_Height(52));
        }
        make.height.offset(BY_Height(57));
    }];
    //城市名
    [_cityLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(ws.searchBgView.mas_left).offset(BY_Width(15));
        make.centerY.equalTo(ws.searchBgView.mas_centerY);
    }];
    //分割线
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(ws.cityLab.mas_right).offset(BY_Width(9));
        make.height.offset(BY_Height(30));
        make.centerY.equalTo(ws.cityLab.mas_centerY);
        make.width.offset(BY_Width(2));
    }];
    //搜索按钮
    [_searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(ws.cityLab.mas_right).offset(BY_Width(20));
        make.centerY.equalTo(ws.searchBgView.mas_centerY);
        make.right.equalTo(ws.searchBgView.mas_right).offset(BY_Width(-9));
    }];
}
-(void)seachBtnClick{
    if (self.delegate && [self.delegate respondsToSelector:@selector(screachClick)]) {
        [self.delegate screachClick];
    }
}
-(void)scanBtnClick{
    if (self.delegate && [self.delegate respondsToSelector:@selector(typeClick)]) {
        [self.delegate typeClick];
    }
}


@end
